package com.jayson.server.catalina;

import java.io.IOException;
import java.io.InputStream;

public class Request {

    private String method;

    private String url;

    private InputStream inputStream;

    private String host;

    public Request() {
    }

    public Request(InputStream inputStream) throws IOException {
        this.inputStream = inputStream;
        int count = 0;
        while (count == 0){
            count = inputStream.available();
        }

        byte[] bytes = new byte[count];
        inputStream.read(bytes);

        String str = new String(bytes);
        String firstLineStr = str.split("\\n")[0];
        String[] strings = firstLineStr.split(" ");
        this.method = strings[0];
        this.url = strings[1];

        String secondLineStr = str.split("\\n")[1];
        this.host = secondLineStr.split(":")[1].trim();

        System.out.println("=======>>>>>>" + this.method);
        System.out.println("=======>>>>>>" + this.url);
        System.out.println("=======>>>>>>" + this.host);

    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }
}
